package com.mapbox.maps.testapp.integration.texture

import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import com.mapbox.maps.testapp.examples.TextureViewActivity
import com.mapbox.maps.testapp.integration.BaseIntegrationTest
import com.mapbox.maps.testapp.integration.launchActivity
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class TextureViewReopenTest : BaseIntegrationTest() {

  @get:Rule
  var activityRule: ActivityScenarioRule<TextureViewActivity> = ActivityScenarioRule(TextureViewActivity::class.java)

  @Test
  @LargeTest
  fun reopenTextureViewActivityHomeButton() {
    for (i in 0 until testRepeatCount) {
      device.waitForIdle()
      device.pressHome()
      device.waitForIdle()
      activityRule.scenario.onActivity {
        device.launchActivity(it, TextureViewActivity::class.java)
        device.waitForIdle()
      }
    }
  }

  @Test
  @LargeTest
  fun reopenTextureViewActivityPowerButton() {
    for (i in 0 until testRepeatCount) {
      device.waitForIdle()
      device.sleep()
      device.waitForIdle()
      device.wakeUp()
      activityRule.scenario.onActivity {
        device.launchActivity(it, TextureViewActivity::class.java)
        device.waitForIdle()
      }
    }
  }
}